/**
 * Created by wady on 2017/9/18.
 */
'use strict';
angular.module('backofficeApp.userInvitation.controller', []).filter('object2Array', function () {
    return function (input) {
        var out = [];
        for (i in input) {
            out.push(input[i]);
        }
        return out;
    }
}).controller('userInvitationCtrl', ['$scope', '$http', '$compile', function ($scope, $http, $compile) {

    $scope.bindInviterAndInvitee = function() {
        $(".alert").css("display","block");
        var inviterMobilePhone = $("#inviterMobilePhone").val();
        if(!inviterMobilePhone) {
            alert("邀请人手机号不能为空!");
            $(".alert").css("display","none");
            return;
        }
        if(inviterMobilePhone.length != 11) {
            alert("请输入11位邀请人手机号!");
            $(".alert").css("display","none");
            return;
        }
        var inviteeMobilePhone = $("#inviteeMobilePhone").val();
        if(!inviteeMobilePhone) {
            alert("被邀请人手机号不能为空!");
            $(".alert").css("display","none");
            return;
        }
        if(inviteeMobilePhone.length != 11) {
            alert("请输入11位被邀请人手机号!");
            $(".alert").css("display","none");
            return;
        }
        if(inviterMobilePhone == inviteeMobilePhone) {
            alert("邀请人和被邀请人手机号不能一样...!");
            $(".alert").css("display","none");
            return;
        }
        var params = {"inviterMobilePhone" : inviterMobilePhone, "inviteeMobilePhone" : inviteeMobilePhone};
        $http.post('http://' + backOfficeHost + '/rest/v1.0/userInvitation/bindInviterAndInvitee', params).then(
            function successCallback(response) {
                $(".alert").css("display","none");
                var data = response.data.data;
                alert("" + data);
            }, function errorCallback(response) {
                $(".alert").css("display","none");
                alert('失败!');
            })
    };
}])